\ProvidesClass{ttextemp2}[2023/09/11 Simple LaTeX Class Template]

% 基于 article 类，您也可以选择其他基类
% \LoadClass{article}  % 英文
\LoadClass[14pt, a4paper, openany, linespread=1.3]{ctexbook}  % 中文

% % 导入宏包
% \RequirePackage[T1]{fontenc}
% \RequirePackage{graphicx}
% \RequirePackage{geometry}
% \RequirePackage{lipsum} 
% \RequirePackage{titlesec}
% \RequirePackage{color}

% % 页面边距设置

% % 自定义颜色
% \definecolor{sectioncolor}{RGB}{50, 50, 250}
% % 自定义标题格式
% \titleformat{\section}
% {\color{sectioncolor}\large\bfseries}
% {\color{sectioncolor}\thesection}{1em}{}

% \titleformat{\subsection}
% {\color{sectioncolor}\normalsize\bfseries}
% {\color{sectioncolor}\thesubsection}{1em}{}

% % 自定义命令
% \newcommand{\important}[1]{\textbf{\color{red}#1}}

% \usepackage{biblatex}
% \addbibresource[location=local]{reference.bib}
% \endinput


\RequirePackage{amsmath, amsthm, amssymb, graphicx, ulem}
\RequirePackage{tikz}
\RequirePackage{calc}
\RequirePackage{geometry}

% \usepackage{newtxtext,newtxmath}    % Times
% \usepackage{newpxtext,mathpazo}   % Pazo
% \usepackage{fouriernc}            % Fourier
% \usepackage{mathdesign}
% \usepackage{cmbright}
% \usepackage{eulerpx}

% \usepackage{xeCJK}
\setCJKmainfont{方正新书宋简体}[BoldFont=思源黑体 CN Medium]
\catcode`\。=\active
\newcommand{。}{\ifmmode\text{．}\else ．\fi}

\newcommand{\textbb}[1]{\textbf{\heiti #1}}
\newcommand{\RR}{\mathbb{R}}
\newcommand{\QQ}{\mathbb{Q}}
\newcommand{\CC}{\mathbb{C}}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\NN}{\mathbb{N}}
\newcommand{\NP}{\mathbb{N^+}}

% \RequirePackage{extsizes}
% \usepackage{bm}
% \setmainfont{TIMES.TTF}
% 在导言区里的注释
% \newtheorem{example}{例}[section]
% \newtheorem{practice}{练习}[section]
% \setlength{\lineskip}{\baselineskip-\ccwd}
% \setlength{\lineskiplimit}{2.5pt}
\geometry{left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm}
% \geometry{scale=0.775}

\usepackage{scrextend}
\changefontsizes[14pt]{14pt}

\usepackage{setspace}
\doublespacing

% 定义颜色
\definecolor{winered}{rgb}{0.5,0,0}
\definecolor{structurecolor}{RGB}{122,122,142}
\definecolor{main}{HTML}{000000}
\definecolor{second}{HTML}{000000}
\definecolor{third}{HTML}{000000}

% 定义引用的颜色
\usepackage{hyperref}
\hypersetup{colorlinks = true, linktoc=all, linkcolor=black, urlcolor=winered}

% ------------------------------------------------------------%
% 定义定理环境
% \usepackage{amsthm}
\newtheoremstyle{defstyle}{3pt}{3pt}{\kaishu}{-3pt}{\bfseries\color{structurecolor}}{}{0.5em}{\indent ［\thmname{#1} \thmnumber{#2}］ \thmnote{(#3)}}
\newtheoremstyle{thmstyle}{3pt}{3pt}{\kaishu}{-3pt}{\bfseries\color{structurecolor}}{}{0.5em}{\indent［\thmname{#1} \thmnumber{#2}］ \thmnote{(#3)}}
\newtheoremstyle{prostyle}{3pt}{3pt}{\kaishu}{-3pt}{\bfseries\color{structurecolor}}{}{0.5em}{\indent［\thmname{#1} \thmnumber{#2}］ \thmnote{(#3)}}

% \theoremstyle{thmstyle} %theorem style
%   \newtheorem{theorem}{定理}[section]
% \theoremstyle{defstyle} % definition style
%   \newtheorem{definition}{定义}[section]
%   \newtheorem{lemma}[theorem]{引理}
%   \newtheorem{corollary}[theorem]{推论}
% \theoremstyle{prostyle} % proposition style
%   \newtheorem{proposition}[theorem]{命题}
%   \newtheorem{example}[theorem]{例题}
%   \newtheorem{exercises}[theorem]{练习}
%   \newtheorem{remark}{注}[section]

\usepackage{tcolorbox}
\tcbuselibrary{most}

\definecolor{BKG}{HTML}{F5F5F5}
\definecolor{ctheo}{HTML}{364f6b}
\definecolor{cexe}{HTML}{81B0D2}
\definecolor{cdef}{HTML}{8DCFC9}
\definecolor{crem}{HTML}{2b2b2b}
\definecolor{cmyr}{HTML}{16160e}
\definecolor{ccor}{HTML}{b3ada0}

\newtcbtheorem[number within=section]{defn}%
{定义}{breakable, enhanced,colback=BKG,colframe=cdef,fonttitle=\bfseries}{def}

\newtcbtheorem[number within=section]{exe}%
{练习}{breakable, enhanced,colback=BKG,colframe=cexe,fonttitle=\bfseries}{exe}

\newtcbtheorem[number within=section]{exam}%
{例}{breakable, enhanced,colback=BKG,colframe=cexe,fonttitle=\bfseries}{exe}

\newtcbtheorem[number within=section]{lemma}%
{引理}{breakable, enhanced,colback=BKG,colframe=ctheo,fonttitle=\bfseries}{lem}

% 使用另一个计数器 use counter from=lemma
\newtcbtheorem[number within=section]{them}%
{定理}{breakable, enhanced,colback=BKG,colframe=ctheo,fonttitle=\bfseries}{them}

\newtcbtheorem[number within=section]{rem}%
{注}{breakable, enhanced,colback=BKG,colframe=crem,fonttitle=\bfseries}{cri}

\newtcbtheorem[number within=section]{myre}%
{笔者注}{breakable, enhanced,colback=BKG,colframe=crem,fonttitle=\bfseries}{cri}

\newtcbtheorem[use counter from=them,number within=section]{coro}%
{推论}{breakable, enhanced,colback=BKG,colframe=ccor,fonttitle=\bfseries}{cor}

\newenvironment{exercise}{
    \begin{exe}{}{}\setlength{\parskip}{0.5em}
}{
    \end{exe}
}

% \newenvironment{theorem}{
    % \begin{them}{}{}
% }{
    % \end{them}
% }

\newenvironment{theorem}[1][]{
    \begin{them}{#1}{}\setlength{\parskip}{0.5em}
}{
    \end{them}
}

\usepackage{indentfirst}

\newenvironment{example}[1][]{
    \begin{exam}{#1}{}\setlength{\parskip}{0.5em}
}{
    \end{exam}
}

\newenvironment{myremark}[1][]{
    \begin{myre}{#1}{}
        \setlength{\parindent}{2em}
        \indent
        \setlength{\parskip}{0.5em}}{\end{myre}}

\newenvironment{definition}[1][]{
    \begin{defn}{#1}{}\setlength{\parskip}{0.5em}
}{
    \end{defn}
}

\newenvironment{corollary}[1][]{
    \begin{coro}{#1}{}\setlength{\parskip}{0.5em}
}{
    \end{coro}
}

\newenvironment{remark}[1][]{
    \begin{rem}{#1}{}\setlength{\parskip}{0.5em}
}{
    \end{rem}
}
\renewenvironment{proof}[1][证明]{\par{\textbf{#1.}} \;\fangsong}{\qed\par}
\newenvironment{solution}{\par{\textbf{解.}} \;\kaishu}{\qed\par}
\newcommand{\intro}[1]{\rightline{\parbox[t]{5cm}{\footnotesize \fangsong\quad\quad #1 }}}
% ------------------------------------------------------------%

\newenvironment{introduction}{
  \begin{quotation}
    \fangsong  
}{
  \vspace*{1pt}
  \end{quotation}
}

% 设置章形式
\usepackage{titlesec, titletoc}
\linespread{1.4} 	

\usepackage{fancyhdr}
\fancyhf{}
\renewcommand{\headrule}{\color{structurecolor}\hrule width\textwidth}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{1pt}
\fancypagestyle{plain}{\renewcommand{\headrulewidth}{0pt}\fancyhf{}\renewcommand{\headrule}{}}

\fancyhead[c]{\color{structurecolor}\kaishu\rightmark}
\fancyfoot[c]{\color{structurecolor}\small\thepage}

\titleformat{\chapter}[display]{\Large}
{\color{structurecolor}\filright \parbox{1cm}{\vbox to 1.5cm{\vfill\hbox to 4cm{\hfill\Huge \bfseries \color{structurecolor}{Chapter} \thechapter \hfill}}}}
{-2ex}
{\color{structurecolor} \huge\bfseries \filright \vspace*{1em}}
[\vspace*{5pt} {\titlerule[2pt]}]


\titleformat{\section}[frame]{\normalfont\color{main}}{\footnotesize \enspace \large \textcolor{main}{\S \,\thesection}\enspace}{14pt}{\Large\filcenter \bf \kaishu }

\titleformat{\subsection}[hang]{\bfseries}{\large\bfseries\color{main}\thesubsection\enspace}{1pt}{\color{main}\large\bfseries\filright}

\titleformat{\subsubsection}[hang]{\bfseries}{\large\bfseries\color{main}\thesubsubsection\enspace}{1pt}{\color{main}\large\bfseries\filright}
% ------------------------------------------------------------%

% 设置封面
\usepackage{titling}
\renewcommand*{\maketitle}{
    \begin{titlepage}
        \newgeometry{margin = 0in}
        \parindent=0pt
        \includegraphics[width=\linewidth]{cover.png}
        \vfill
        \begin{center}
            \parbox{0.618\textwidth}{
            \hfill {\filleft \bfseries \Huge \thetitle} \\[0.6pt]  
            \rule{0.618\textwidth}{4pt} \\ 
        }
        \end{center}
        % \vfill
        \begin{center}
            \parbox{0.618\textwidth}{
                \hfill\Large
                \kaishu 
                \begin{tabular}{r|}
                作者：\theauthor \\ 
                时间：\thedate \\
                \end{tabular}
            }
        \end{center}
        \vfill
        \begin{center}
            \parbox[t]{0.7\textwidth}{\centering \kaishu }
        \end{center}
        \vfill
    \end{titlepage}
    \restoregeometry
    \thispagestyle{empty}
}
% ------------------------------------------------------------%